package org.lt.resume.service.subcompanyservice;

import java.util.List;

import org.lt.resume.dao.subcompanydao.SubCompanyDAO;
import org.lt.resume.domain.company.SubCompanyInfo;
import org.lt.resume.domain.users.User;
import org.lt.resume.service.subcompanyserviceInterface.SubCompanyServiceInterface;
import org.lt.resume.util.common.daoInterface.PagenateDAOInterface;

public class SubCompanyServiceImpl implements SubCompanyServiceInterface {

	private SubCompanyDAO subCompanyDAO;

	private PagenateDAOInterface pagenateDAO;

	private final int pagesize = 10;

	public void addSubCompanyInfo(SubCompanyInfo subcompany) {
		subCompanyDAO.addSubcompany(subcompany);
	}

	public void updateSubCompany(SubCompanyInfo subcompany) {
		subCompanyDAO.updateSubcompany(subcompany);
	}

	public boolean deleteSubcompany(String name){
		SubCompanyInfo s = subCompanyDAO.findSubcompany(name);
		if (s== null) {
			return false;
		}
		subCompanyDAO.deleteSubcompany(s);
		return true;
		
	}

	public List searchSubCompanyInfo(int currentpage) {
		String sql = "from SubCompanyInfo as subcompany";
		String hql = "select count(*) from SubCompanyInfo as subcompany";
		int totalCount = pagenateDAO.getRowsCount(hql);
		if (totalCount < currentpage * pagesize) {

			currentpage = totalCount / pagesize;
		}
		List list = pagenateDAO.getData(currentpage, pagesize, sql);
		return list;
	}
	public List seachSubCompanyInfoForTable(String name) {

		List list = subCompanyDAO.findSubCompanyInfoByName(name);
		return list;
	}
	
	public SubCompanyDAO getSubCompanyDAO() {
		return subCompanyDAO;
	}

	public void setSubCompanyDAO(SubCompanyDAO subCompanyDAO) {
		this.subCompanyDAO = subCompanyDAO;
	}

	public PagenateDAOInterface getPagenateDAO() {
		return pagenateDAO;
	}

	public void setPagenateDAO(PagenateDAOInterface pagenateDAO) {
		this.pagenateDAO = pagenateDAO;
	}

}
